# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""

import pandas as pd
import numpy as np

df = pd.DataFrame({'key1' : ['a', 'a', 'b', 'b', 'a'],
    'key2' : ['one', 'two', 'one', 'two', 'one'],
    'data1' : np.random.randn(5),
    'data2' : np.random.randn(5)})

'''print(df)
grouped = df['data1'].groupby(df['key1'])
print(grouped.mean())
for name, group in df.groupby('key2'):
    print (name)
    print (group)
    '''
for (k1,k2), group in df.groupby(['key1','key2']):
    print (k1,k2)
    print (group)
#https://blog.csdn.net/qq_24753293/article/details/78338263